package com.zzyl.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.entity.Reservation;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.TimeCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
public class AppReservationController extends BaseController {

    @Autowired
    private ReservationService reservationService;


    //查询取消预约次数
    @GetMapping("/customer/reservation/cancelled-count")
    public ResponseResult getCancelledCount() {
        Integer count = reservationService.getCancelledCount();
        return success(count);
    }

    //查询每个时间段剩余预约次数
    @GetMapping("/customer/reservation/countByTime")
    public ResponseResult getTimeCount(Long time) {
        List<TimeCountVo> list = reservationService.getTimeCount(time);
        return success(list);
    }

    //新增预约
    @PostMapping("/customer/reservation")
    public ResponseResult add(@RequestBody Reservation reservation){
        reservationService.add(reservation);
        return success();
    }

    //分页查询预约
    @GetMapping("/customer/reservation/page")
    public ResponseResult getByPage(Integer status,
                                    @RequestParam(defaultValue = "1")Integer pageNum,
                                    @RequestParam(defaultValue = "10")Integer pageSize){
        PageResponse<Reservation>page=reservationService.getByPage(status,pageNum,pageSize);
        return success(page);
    }

    //取消预约
    @PutMapping("/customer/reservation/{id}/cancel")
    public ResponseResult cancel(@PathVariable Long id){
        Reservation reservation = new Reservation();
        reservation.setId(id);
        reservation.setStatus(2);
        reservationService.updateById(reservation);
        return success();
    }


}
